/*
 * Copyright (c) 2007 jNetX.
 * http://www.jnetx.com
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * jNetX. You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license
 * agreement you entered into with jNetX.
 *
 * $Id$
 */
package com.jnetx.javax.sip.header;

import javax.sip.header.ContentEncodingHeader;
import java.text.ParseException;

/**
 * @author <a href="mailto:dparhonin@jnetx.ru">Dmitry Parhonin</a>
 * @version $Revision$
 */
public class ContentEncodingHeaderImpl extends HeaderBase implements ContentEncodingHeader {
    private String encoding;

    private static final ContentEncodingHeaderParser parser = new ContentEncodingHeaderParser();

    public ContentEncodingHeaderImpl() {
        super(ContentEncodingHeader.NAME);
    }

    ContentEncodingHeaderImpl(byte[] data, int start, int end) {
        super(ContentEncodingHeader.NAME, data, start, end);
    }

    public Object clone() {
        final ContentEncodingHeaderImpl header = new ContentEncodingHeaderImpl();
        header.cloneBase(this);
        if (parsed){
            header.encoding = this.encoding;
        }
        return header;
    }

    protected HeaderParser getParser() {
        return parser;
    }

    protected String getValueAsString() {
        return encoding;
    }

    /**
     * Sets the encoding of an EncodingHeader.
     *
     * @param encoding the new string value defining the encoding.
     * @throws java.text.ParseException which signals that an error has been reached
     *                                  unexpectedly while parsing the encoding value.
     */

    public void setEncoding(String encoding) throws ParseException {
        parse();
        this.encoding = encoding;
        invalidateHeaderData();
    }

    /**
     * Gets the encoding of an EncodingHeader. Returns null if no
     * encoding is defined in an EncodingHeader.
     *
     * @return the string value identifing the encoding
     */
    public String getEncoding() {
        parse();
        return encoding;
    }
}
/*
 * $Log$
 */